{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from torch.nn import Linear\n",
    "from torch import nn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-7.21]\n",
      " [-6.6 ]\n",
      " [-6.07]\n",
      " [-5.78]\n",
      " [-4.06]\n",
      " [-0.83]\n",
      " [ 6.69]\n",
      " [ 7.44]\n",
      " [ 9.65]\n",
      " [ 9.84]] \n",
      " [[-9.88]\n",
      " [-8.79]\n",
      " [-5.52]\n",
      " [-4.67]\n",
      " [-3.83]\n",
      " [ 2.03]\n",
      " [ 5.18]\n",
      " [ 7.18]\n",
      " [ 8.15]\n",
      " [ 9.94]]\n"
     ]
    }
   ],
   "source": [
    "# 获得训练数据\n",
    "import numpy as np\n",
    "import random\n",
    "x = sorted([random.randint(-1000, 1000) * 0.01 for i in range(10)])\n",
    "y = sorted([random.randint(-1000, 1000) * 0.01 for i in range(10)])\n",
    "x_train = [[i] for i in x]\n",
    "y_train = [[i] for i in y]\n",
    "x_train = np.array(x_train)\n",
    "y_train = np.array(y_train)\n",
    "\n",
    "print(x_train, '\\n', y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEACAYAAACwB81wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAEAhJREFUeJzt3V+MXOV9xvHnQd6VJqmMKAxGIslMGposqWoRK6aRUlWzihZMpQqCogR60X+rCGQi9aKVAHHhbdUL6IVvUu1NGCEqweL0gjZUarCjeCJZvegKShcr2Lhqz/InwTkKBCXqSt7gXy92bA9mdu35c+ac3ff7kUaec87MeX86Ozz78u573nFECACw811TdgEAgMkg8AEgEQQ+ACSCwAeARBD4AJAIAh8AEjGWwLf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A7ZP2X7d9sNl11Mm25nt/7L9n7b/o+x6Jsl22/ZZ2ys9+66zfdT2adsv2r62zBonZZNrMXBWlLm0Qt+btmzfKunrkm6VdJekRdupjfMf7rlp7ftlFzNJtq+R9A+S7pT0O5Lutz1TblWlOi+pFRFfiIjbyy5mwp7Sxueg1yOSfhARn5P0Q0mPTryqcvS7FtKAWVFa4G9x09bdkp6LiF9HRCbpjKTUPuip/YLrdbukMxGxGhHrkp7TxmciVVaia15FxAlJ7122+25JT3efPy3pnokWVZJNroU0YFZU8YN0s6Q3e7bf7u5LyUO2X7H9ZCr/y9rj8p//W0rv598rJL1oe9n2N8supgJujIizkhQR70i6seR6yjZQVhQa+LaP2V7pebza/fePimy36q5wXRYlfSYibpP0jqTD5VaLkn05Ir4o6Q+18R83d61/WMqzTgbOinHOw/+IiJgb4m1vS/pkz/Ynuvt2jAGuy3ckbXY38071tqRP9WzvuJ//ICLip91/c9vPa2PI60S5VZXqrO09EXHW9k2SflZ2QWWJiLxn86qyoipDOr3jUN+TdJ/taduf1sZNW8nMTuh+iC+4V9LJsmopybKkW7pLbE9Luk8bn4nk2P6Y7d/oPv+4pDuU3ufB+mg+/Fn3+Z9K+pdJF1SiD12LYbKi0B7+VmzfI+nbkm7Qxk1br0TEXRHxY9vflfRjSeuSDkZaNwv8ve3btDE7I5P0QLnlTFZEfGD7W5KOaqND0o6I10ouqyx7JD3fXX5kl6RnIuJoyTVNjO1nJbUkXW/7DUmHJD0u6Z9s/4WkVW3M6NvxNrkWs4NmBTdeAUAiqjKkAwAoGIEPAIkg8AEgEQQ+ACSCwAeARBD4AJAIAh8AEkHgA0Ai/h8ouuEJoRhXmwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fe4187b2390>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画图\n",
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(x_train, y_train)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "-7.2100\n",
      "-6.6000\n",
      "-6.0700\n",
      "-5.7800\n",
      "-4.0600\n",
      "-0.8300\n",
      " 6.6900\n",
      " 7.4400\n",
      " 9.6500\n",
      " 9.8400\n",
      "[torch.FloatTensor of size 10x1]\n",
      " \n",
      " \n",
      "-9.8800\n",
      "-8.7900\n",
      "-5.5200\n",
      "-4.6700\n",
      "-3.8300\n",
      " 2.0300\n",
      " 5.1800\n",
      " 7.1800\n",
      " 8.1500\n",
      " 9.9400\n",
      "[torch.FloatTensor of size 10x1]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 将numpy变量转化为tensor\n",
    "x_train = torch.from_numpy(x_train)\n",
    "y_train = torch.from_numpy(y_train)\n",
    "x_train = x_train.float()\n",
    "y_train = y_train.float()\n",
    "print(x_train, '\\n', y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义模型， 应当包含 __init__（）函数和forward()函数\n",
    "class LinearRegression(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(LinearRegression, self).__init__()\n",
    "        self.linear = Linear(1, 1)\n",
    "    \n",
    "    def forward(self, x) :\n",
    "        out = self.linear(x)\n",
    "        return out\n",
    "if torch.cuda.is_available():\n",
    "    model = LinearRegression().cuda()\n",
    "else :\n",
    "    model = LinearRegression()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义损失函数和优化函数\n",
    "criterison = nn.MSELoss()\n",
    "optimizer = torch.optim.SGD(model.parameters(), lr = 1e-3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch[20/1000], loss : 3.845105\n",
      "Epoch[40/1000], loss : 2.739876\n",
      "Epoch[60/1000], loss : 2.704095\n",
      "Epoch[80/1000], loss : 2.689542\n",
      "Epoch[100/1000], loss : 2.676452\n",
      "Epoch[120/1000], loss : 2.664375\n",
      "Epoch[140/1000], loss : 2.653225\n",
      "Epoch[160/1000], loss : 2.642932\n",
      "Epoch[180/1000], loss : 2.633429\n",
      "Epoch[200/1000], loss : 2.624657\n",
      "Epoch[220/1000], loss : 2.616558\n",
      "Epoch[240/1000], loss : 2.609081\n",
      "Epoch[260/1000], loss : 2.602178\n",
      "Epoch[280/1000], loss : 2.595806\n",
      "Epoch[300/1000], loss : 2.589923\n",
      "Epoch[320/1000], loss : 2.584491\n",
      "Epoch[340/1000], loss : 2.579478\n",
      "Epoch[360/1000], loss : 2.574849\n",
      "Epoch[380/1000], loss : 2.570575\n",
      "Epoch[400/1000], loss : 2.566631\n",
      "Epoch[420/1000], loss : 2.562988\n",
      "Epoch[440/1000], loss : 2.559626\n",
      "Epoch[460/1000], loss : 2.556522\n",
      "Epoch[480/1000], loss : 2.553656\n",
      "Epoch[500/1000], loss : 2.551010\n",
      "Epoch[520/1000], loss : 2.548568\n",
      "Epoch[540/1000], loss : 2.546313\n",
      "Epoch[560/1000], loss : 2.544232\n",
      "Epoch[580/1000], loss : 2.542310\n",
      "Epoch[600/1000], loss : 2.540536\n",
      "Epoch[620/1000], loss : 2.538898\n",
      "Epoch[640/1000], loss : 2.537386\n",
      "Epoch[660/1000], loss : 2.535990\n",
      "Epoch[680/1000], loss : 2.534701\n",
      "Epoch[700/1000], loss : 2.533512\n",
      "Epoch[720/1000], loss : 2.532413\n",
      "Epoch[740/1000], loss : 2.531399\n",
      "Epoch[760/1000], loss : 2.530463\n",
      "Epoch[780/1000], loss : 2.529599\n",
      "Epoch[800/1000], loss : 2.528801\n",
      "Epoch[820/1000], loss : 2.528064\n",
      "Epoch[840/1000], loss : 2.527384\n",
      "Epoch[860/1000], loss : 2.526757\n",
      "Epoch[880/1000], loss : 2.526177\n",
      "Epoch[900/1000], loss : 2.525642\n",
      "Epoch[920/1000], loss : 2.525148\n",
      "Epoch[940/1000], loss : 2.524692\n",
      "Epoch[960/1000], loss : 2.524271\n",
      "Epoch[980/1000], loss : 2.523883\n",
      "Epoch[1000/1000], loss : 2.523524\n"
     ]
    }
   ],
   "source": [
    "# 开始训练模型\n",
    "from torch.autograd import Variable\n",
    "# 定义要跑的批(epoch)数\n",
    "num_epochs = 1000\n",
    "for epoch in range(num_epochs) :\n",
    "    # 获得每一批数据的输出\n",
    "    if torch.cuda.is_available() :\n",
    "        inputs = Variable(x_train).cuda()\n",
    "        target = Variable(y_train).cuda()\n",
    "    else :\n",
    "        inputs = Variable(x_train)\n",
    "        target = Variable(y_train)\n",
    "    # forward前向计算\n",
    "    out = model(inputs)\n",
    "    loss = criterison(out, target)\n",
    "    # backward 计算误差项及更新参数\n",
    "    optimizer.zero_grad()\n",
    "    loss.backward()\n",
    "    optimizer.step()\n",
    "    \n",
    "    # 一轮训练结束， 输出信息\n",
    "    if(epoch + 1) % 20 == 0 :\n",
    "        print('Epoch[{}/{}], loss : {:.6f}'.format(epoch + 1, num_epochs, loss.data[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(\n",
       "  (linear): Linear(in_features=1, out_features=1)\n",
       ")"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将模型变成测试模式\n",
    "model.eval()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7fe4187b22b0>]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEACAYAAACwB81wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAHiJJREFUeJz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KrMrCeAmfUGPg24HoAXiYSXmR0GtIp32O+Oc26hc+5A59zBzrkO+B+QYxIR9o0xszPx7YF+zrlNAZUxEzjEzNpHZlIMxC8ADIPHgMXOuXFBFwLgnLvVOdfOOXcw/s/p7YDDnkhr4vPIzxpAb4J/oPwZ0N3M9owMsnoT7INkY8cFrgWRjy8FGh1MJGyE34grgPFmlglsBK4MuB7wT8UfM7MFwCYg0B+InXCE45/iAA8CrYHSyC7Y051z1ySyAOdcnZldh58xlAE86pwLdJYHgJmdAgwCFpjZXPz/t1udc68HW1koXY9fod8KWAFcFmQxzrkZZvYcMBeojfz3oSBqMbOngDxgv8izziJgNPCsmf0BP2vvokavo4VXIiLpISwtHRERiTMFvohImlDgi4ikCQW+iEiaUOCLiKQJBb6ISJpQ4IuIpAkFvohImvh/S1jmJhaf3b4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fe4188684e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 测试结果与真实结果作比较\n",
    "predict = model(Variable(x_train))\n",
    "predict = predict.data.numpy()\n",
    "plt.plot(x_train.numpy(), y_train.numpy(), 'ro', label='Original data')\n",
    "plt.plot(x_train.numpy(), predict, label='Fitting Line')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
